<?php
require_once('includes/config.php');
require_once('includes/functions/func.global.php');
require_once('includes/classes/class.template_engine.php');
require_once('includes/lang/lang_'.$config['lang'].'.php');

if(isset($_GET['js']))
{
	echo "document.write(\"<iframe src='".$config['site_url']."digframe.php?id=\"+escape(story_id)+\"' height='80' width='52' frameborder='0' scrolling='no'></iframe>\")";
	exit;
}

// Start the session
session_start();

// Connect to the database
db_connect($config);

// Check if the user has a remember cookie set
checkremember($config);

$query = "SELECT story_id,story_digs FROM ".$config['db']['pre']."stories WHERE story_id='".addslashes($_GET['id'])."' LIMIT 1";
$query_result = @mysql_query ($query) OR error(mysql_error(), __LINE__, __FILE__, 0, '', '');
$story = @mysql_fetch_array($query_result);

if(!isset($story['story_id']))
{
	exit('Story not found');
}

if(isset($_SESSION['duser']['id']))
{
	$user_dig = mysql_num_rows(mysql_query("SELECT 1 FROM ".$config['db']['pre']."digs WHERE user_id='".$_SESSION['duser']['id']."' AND story_id='".addslashes($_GET['id'])."' LIMIT 1"));
}
else
{
	$user_dig = 0;
}

$page = new HtmlTemplate ("templates/" . $config['tpl_name'] . "/digframe.html");
$page->SetParameter ('STORY_DIGS', $story['story_digs']);
$page->SetParameter ('STORY_ID', $story['story_id']);
$page->SetParameter ('USER_DUGG',$user_dig);
if(isset($_SESSION['duser']['id']))
{
	$page->SetParameter ('LOGGEDIN', 1);
}
else
{
	$page->SetParameter ('LOGGEDIN', 0);
}
$page->CreatePageEcho($lang,$config);
?>